<template>
	<!-- 银行卡列表 -->
	<view class="bankCard">
		<view class="bankCard-main" v-if="cardList.length > 0">
			<view class="bankCard-item" v-for="(item, index) in cardList" :key="item.id">
				<view class="bankCard-item-info">
					<view class="card-name">{{item.bank_name}}</view>
					<view class="info-cardNum">
						{{item.bank_card}}
					</view>
				</view>
				<view class="bankCard-item-btn">
					<view class="btn" @click="getpayunbindBankCard(item.id)">解除绑定</view>
				</view>
			</view>
		</view>

		<view style="margin: 100rpx 0" v-else>
			<u-empty mode="list" icon="http://cdn.uviewui.com/uview/empty/list.png"></u-empty>
		</view>

		<view class="bankCard-btn" :style="bottomStyle">
			<view class="btn" @click="gotopath">添加银行卡</view>
		</view>
	</view>
</template>

<script>
import { payunbindBankCard, paybankCardList } from '../../api/payment/index.js';
export default {
	data() {
		return {
			cardList: []
		};
	},
	computed: {
		bottomStyle() {
			const systemInfo = uni.getSystemInfoSync();
			const { safeAreaInsets } = systemInfo;
			const bottomSafeAreaHeight = safeAreaInsets.bottom || 0;
			return `padding-bottom: ${bottomSafeAreaHeight ? bottomSafeAreaHeight + 'px' : '20rpx'}`;
		}
	},
	onLoad() {
		this.getpaybankCardList();
	},
	methods: {
		// 银行卡列表
		async getpaybankCardList() {
			try {
				const resData = await paybankCardList();
				this.cardList = resData.data;
			} catch (e) {
				throw Error(e);
			}
		},

		// 解绑
		async getpayunbindBankCard(bank_card) {
			try {
				const resData = await paybankCardList({
					bank_card
				});
				uni.showToast({
					title: '解绑成功',
					icon: 'none'
				});
			} catch (e) {
				throw Error(e);
			}
		},

		gotopath() {
			uni.navigateTo({
				url: '/pages/addCard/addCard'
			});
		}
	}
};
</script>

<style>
page {
	height: 100%;
}
</style>

<style scoped lang="scss">
.bankCard {
	.bankCard-main {
		box-sizing: border-box;
		padding: 20rpx;
		.bankCard-item {
			box-sizing: border-box;
			padding: 30rpx;
			background-color: #fff;
			border-radius: 20rpx;
			margin-bottom: 20rpx;
			.bankCard-item-info {
				.card-name {
					font-size: 28rpx;
					color: #444;
					margin-bottom: 30rpx;
					font-weight: bold;
				}
				.info-cardNum {
					padding: 20rpx 0px;
					padding-top: 0rpx;
					font-size: 28rpx;
					color: #444;
				}
			}
			.bankCard-item-btn {
				border-top: 1px #f3f3f3 solid;
				padding-top: 20rpx;
				display: flex;
				justify-content: flex-end;
				.btn {
					width: 160rpx;
					text-align: center;
					background-color: #f3f3f3;
					color: #444;
					font-size: 26rpx;
					height: 60rpx;
					line-height: 60rpx;
					border-radius: 8rpx;
				}
			}
		}
	}
	.bankCard-btn {
		box-sizing: border-box;
		padding: 20rpx;
		padding-bottom: 0px;
		background-color: #fff;
		position: fixed;
		bottom: 0px;
		left: 0px;
		width: 100%;
		.btn {
			background-color: #e43927;
			color: #fff;
			height: 80rpx;
			border-radius: 8px;
			line-height: 80rpx;
			text-align: center;
		}
	}
}
</style>
